package com.gitee.zjbqdzq.entity;

import cn.hutool.core.util.IdUtil;
import com.gitee.zjbqdzq.Main2;
import jakarta.persistence.*;
import lombok.Data;

import java.io.Serializable;

@Entity
@Data
public class PlayUrlList implements Serializable {

    @Id
    private Long id;
    @Column
    private Boolean huaweiSound;
    @Column
    private Long uploadId;
    @Column
    private Integer fileSize;
    @Column
    private Integer width;
    @Column
    private String type;
    @Column
    private Integer sampleSize;
    @Column
    private Integer qualityLevel;
    @Column
    private Integer version;
    @Column
    @Lob
    private String url;
    @Column
    private Integer height;
    @Column
    private Boolean decrypted;

    @ManyToOne(fetch = FetchType.LAZY)
    private Track track;

    public static PlayUrlList build(TrackInfoResult.TrackInfo.PlayUrlList playUrlList) {
        PlayUrlList playUrlList1 = new PlayUrlList();
        playUrlList1.setUploadId(playUrlList.getUploadId());
        playUrlList1.setFileSize(playUrlList.getFileSize());
        playUrlList1.setWidth(playUrlList.getWidth());
        playUrlList1.setType(playUrlList.getType());
        playUrlList1.setSampleSize(playUrlList.getSampleSize());
        playUrlList1.setQualityLevel(playUrlList.getQualityLevel());
        playUrlList1.setVersion(playUrlList.getVersion());
        playUrlList1.setUrl(playUrlList.getUrl());
        playUrlList1.setHeight(playUrlList.getHeight());
        playUrlList1.setHuaweiSound(playUrlList.getHuaweiSound());
        playUrlList1.setDecrypted(false);
        playUrlList1.setId(IdUtil.getSnowflakeNextId());
        return playUrlList1;
    }

    public void decrypt() {
        this.url = Main2.parseUrl(this.url);
        this.decrypted = true;
    }
}
